package com.worldtolearn.offer.bu;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import com.worldtolearn.offer.dao.AdressDao;
import com.worldtolearn.offer.entity.Adress;
import com.worldtolearn.offer.entity.Offer;
@Named
public class AdressBu implements IAdressBu, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Inject
	AdressDao adressDao;

	@Override
	public void createAdress(Adress adress) {
		adressDao.createAdresse(adress);

	}

	@Override
	public void deleteAdress(Adress adress) {
		adressDao.deleteAdresse(adress);

	}

	public AdressDao getAdressDao() {
		return adressDao;
	}

	public void setAdressDao(AdressDao adressDao) {
		this.adressDao = adressDao;
	}

	@Override
	public List<String> getDistinctAdresse() {
		List<Adress> list = adressDao.getAllAdresse();
		List<String> listPays = new ArrayList<String>();
		String address;
		for (Adress adress : list) {
			address = adress.getCountry();
			if(!listPays.contains(address)){
				listPays.add(address);
			}
		}
		return listPays;
	}

	@Override
	public List<String> getDistinctAdresseFromList(List<Offer>offers) {
		List<String> listPays = new ArrayList<String>();
		String address;
		for (Offer offer : offers) {
			address = offer.getSupplierOffer().getAdress().getCountry();
			if(!listPays.contains(address)){
				listPays.add(address);
			}
		}
		return listPays;
	}
	
	

}
